package greedy;

import java.util.Arrays;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class eraseOverlapIntervals {
    public int eraseOverlapIntervals(int[][] intervals) {
        Arrays.sort(intervals, (a,b)-> {
            return Integer.compare(a[0],b[0]);
        });
        int count = 0;
        for (int i = 1; i < intervals.length; i++) {
            int[] point = intervals[i];
            int[] pre = intervals[i-1];
            if (point[0] < pre[1]){
                count++;
                point[1] = Math.min(pre[1], point[1]);
            }
        }
        return count;
    }
}
